import wx
from PublicMethod import *
from Constant import *
'''
Cube : this object is used in the map when playing, each cube is referred to a type of game object
'''
class Cube(wx.StaticBitmap):
    '''
    Constructor - Cube
        panel - add cube to the panel
        mainMap - object pointer - MainMap
        imageName - the name of image added to this
        position - current position of this in map (row, column)
        objType - object type of this
    '''
    def __init__(self, panel, mainMap, imageName, objType, position):
        image = PublicMethod.ACT001_getBmpImage(imageName, SIZE_CUBE[0], SIZE_CUBE[1])
        wx.StaticBitmap.__init__(self, panel, -1, image, position)
        self._001_initialInstanceVariable(objType, mainMap)
    '''
    function _001 : initialize the variables used for this object
        objType - game object type of this
        mainMap : object pointer - MainMap
    '''
    def _001_initialInstanceVariable(self, objType, mainMap):
        self.gameObjectType = objType
        self.mainMap = mainMap
    '''
    function SET001 : set this cube to referred object type and image in specific index according to 
                      table - LIST_FILENAME_GAMEOBJECT
        objType - object type of this
        imageIndex - specific image in index of table
    '''
    def SET001_gameObjectType(self, objType, imageIndex):
        #set bitmap image
        imageName = self.mainMap.ACT001_getImageName(objType, imageIndex)
        image = PublicMethod.ACT001_getBmpImage(imageName, SIZE_CUBE[0], SIZE_CUBE[1])
        self.SetBitmap(image)
        #reset variable - gameObjectType
        self.gameObjectType = objType
    '''
    function GET001 : get instance variable - gameObjectType 
    '''
    def GET001_gameObjectType(self):
        return self.gameObjectType
        
''' 
ImageTextCube : A button with image at top and text at down. In addition, when this button

                is clicked, it's background color will be changed, and clicked again, it will
                
                be turn to original state.
'''
class ImageTextCube(wx.Button):
    '''
    Constructor : ImageTextCube
        panel : add cube to the panel
        position : the object position in array user defines
        size : the size of this cube
        text : the label text
        imageName : the name of image added to this
        objNum : defined number of this object
    '''
    def __init__(self, panel, position, size, text, imageName, objNum):
        wx.Button.__init__(self, panel, -1, pos = position, size = size)
        self.SetBackgroundColour("black")
        self._001_initialInstanceVariable(objNum, imageName)
        self._003_createText(text)
        self._002_createImage(imageName, (size[0] - 12, size[0] - 12))
    '''
    function _001 : initialize the variables used for this object
        objNum - defined number of this object
        imageName : the name of image added to this
    '''
    def _001_initialInstanceVariable(self, objNum, imageName):
        #defined number of this object
        self.objNum = objNum
        #the file name of the image
        self.imageName = imageName
        #record whether this object is selected
        self.isSelected = False
        #record position in map
        self.posInMap = None
        #object - StaticBitmap
        self.image = None
        #object - StaticText
        self.label = None
    '''
    function _002 : create image object to this button
        imageName : name of image
        imageSize : size of image (length, width)
    '''
    def _002_createImage(self, imageName, imageSize):
        image = PublicMethod.ACT001_getBmpImage(imageName, imageSize[0], imageSize[1])
        self.image = wx.StaticBitmap(parent = self, bitmap = image)
        self.image.SetPosition(((self.GetSize()[0] - image.GetSize()[0]) / 2, 5))
        self.image.Enable(False)
    '''
    function _003 : create object of label text
        text : showing text of label
    '''
    def _003_createText(self, text):
        self.label = wx.StaticText(self, -1, text)
        self.label.SetForegroundColour("cyan")
        self.label.SetFont(wx.Font(8, wx.NORMAL, wx.NORMAL, wx.NORMAL))
        self.label.SetPosition(((self.GetSize()[0] - self.label.GetSize()[0]) / 2, self.GetSize()[1] - self.label.GetSize()[1] - 5))
    '''
    function ACT001 : destroy all object of this
    '''
    def ACT001_destroy(self):
        self.image.Destroy()
        self.label.Destroy()
        self.Destroy()
    '''
    function SET001 : set instance variable - isSelected, and according to the value of this, changing 
                      background color of this button
    '''
    def SET001_isSelected(self, isSelected):
        self.isSelected = isSelected
        if isSelected :
            bColor = "red"
        else :
            bColor = "black"
        self.SetBackgroundColour(bColor)
    '''
    function SET002 : set instance variable - posInMap
    '''
    def SET002_posInMap(self, posInMap):
        self.posInMap = posInMap
    '''
    function GET001 : get instance variable - objNum
    '''
    def GET001_objNum(self):
        return self.objNum
    '''
    function GET002 : get instance variable - posInMap
    '''
    def GET002_posInMap(self):
        return self.posInMap
    '''
    function GET003 : get instance variable - imageName
    '''
    def GET003_imageName(self):
        return self.imageName
    
'''
ImageCube : A button with full image. when this button is set to be selected, it's border will appear;

            on the contrary, the border disappears when button is set to be unselected.
'''
class ImageCube(wx.BitmapButton):
    '''
    Constructor : ImageCube
        panel : add cube to the panel
        position : the object position in array user defines
        imageSize : the size of passing image (length, width)
        borderWidth : the width of border
        imageName : the name of image added to this
        objName : defined name of this object
    '''
    def __init__(self, panel, position, imageSize, borderWidth, imageName, objName):
        image = PublicMethod.ACT001_getBmpImage(imageName, imageSize[0], imageSize[1])
        wx.BitmapButton.__init__(self, panel, -1, image, size = (imageSize[0], imageSize[1]), pos = position)
        self.SetWindowStyle(wx.BORDER_NONE)
        self.SetBackgroundColour("#FF19FC")
        self._001_initialInstanceVariable(imageName, objName, borderWidth)
    '''
    function _001 : initialize the variables used for this object
        imageName : the name of image added to this
        objName : defined name of this object
        borderWidth : the width of border
    '''
    def _001_initialInstanceVariable(self, imageName, objName, borderWidth):
        self.imageName = imageName
        self.objName = objName
        self.borderWidth = borderWidth
        self.isSelected = False
        self.posInMap = None
    '''
    function ACT001 : destroy this object
    '''
    def ACT001_destroy(self):
        self.Destroy()
    '''
    function SET001 : set instance variable - isSelected, and according to the value of this, appear/
                      disappear the border
    '''
    def SET001_isSelected(self, isSelected):
        self.isSelected = isSelected
        if isSelected :
            image = PublicMethod.ACT001_getBmpImage(self.imageName, self.GetSize()[0] - self.borderWidth, self.GetSize()[1] - self.borderWidth)
        else :
            image = PublicMethod.ACT001_getBmpImage(self.imageName, self.GetSize()[0], self.GetSize()[1])
        self.SetBitmapLabel(image)
    '''
    function SET002 : set instance variable - posInMap
    '''
    def SET002_posInMap(self, posInMap):
        self.posInMap = posInMap
    '''
    function SET003 : set instance variable - imageName and objName, and change the image of this button
    '''
    def SET003_image(self, imageName, objName):
        self.imageName = imageName
        self.objName = objName
        self.SET001_isSelected(self.isSelected)
    '''
    function GET001 : get instance variable - posInMap
    '''
    def GET001_posInMap(self):
        return self.posInMap
    '''
    function GET002 : get instance variable - objName
    '''
    def GET002_objName(self):
        return self.objName
    '''
    function GET001 : get instance variable - isSelected
    '''
    def GET003_isSelected(self):
        return self.isSelected